#ifndef SLEWRATEFILTER_H
#define SLEWRATEFILTER_H

#include "filter.h"

template <typename T>
class SlewRateFilter : Filter<T> {
public:
	SlewRateFilter()
		: value_(0)
		, step_(0)
	{}

	virtual ~SlewRateFilter() {}

	virtual T update(T input) {
		if (step_ <= 0)
			value_ = input;
		else {
			T delta = input - value_;

			if (delta < -step_)
				value_ -= step_;
			else if (delta > step_)
				value_ += step_;
			else
				value_ = input;
		}
		
		return value_;
	}

	virtual T operator()() {
		return value_;
	}
	
	virtual void set(T value) {
		value_ = value;
	}

	void setStep(T step) {
		step_ = step;
	}
	
private:
	T value_;
	T step_;
};

#endif
